import numpy as np
import matplotlib.pyplot as plt

# 读入数据点
points = np.array([(672, 917), (712, 914), (632, 914), (750, 912), (827, 910), (788, 911), (902, 908), (865, 909), (941, 907),
                   (978, 907), (1015, 905), (1124, 904), (1088, 904), (1051, 905), (1160, 903), (1266, 902), (1231, 902),
                   (1196, 902), (1301, 901), (1371, 899), (1336, 900), (1472, 898), (1404, 899), (1438, 898), (1506, 897),
                   (1538, 896), (1604, 895), (1571, 895), (1668, 893), (1636, 894), (1699, 892), (1730, 890)])
x = points[:, 0]
y = points[:, 1]

# 线性拟合
fit = np.polyfit(x, y, 1)

# 计算x轴和y轴的范围
x_min, x_max = 0, np.max(x) * 1.05
y_min, y_max = 0, np.max(y) * 1.05

# 绘制点和线，设置x轴和y轴的范围
plt.scatter(x, y)
plt.plot(x, np.polyval(fit, x), 'r')
plt.xlim(x_min, x_max)
plt.ylim(y_min, y_max)
plt.show()
